<?php
/**
 * PddMallProduct.php class file.
 * @author wudg <544038230@qq.com>
 * @date 2021/1/17- 下午4:35
 */

namespace common\jobs\models;

use common\jobs\services\SyncEsService;
use common\models\pdd\PddMallProduct as BasePddMallProduct;

class PddMallProduct extends BasePddMallProduct
{

    /**
     * 数据变更后同步es
     * @param bool $insert
     * @param array $changedAttributes
     * @throws \yii\base\Exception
     */
    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);
        if ($this->goods_id) {
            $countItems = PddMallProduct::find()->where(['goods_id' => $this->goods_id])->count();
            if ($countItems) {
                $syncEsService = new SyncEsService();
                $syncEsService->syncMallProduct([$this->goods_id]);
            }
        }
    }
}